import Vue from 'vue'
import VueRouter from 'vue-router'
import LoginView from '../views/LoginView.vue'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        component: LoginView,
        meta: {
            title: '用户登录'
        }
    },
    {
        path: '/admin',
        redirect: '/admin/user/list',
        component: () => import('../views/AdminView.vue'),
        children: [
            {
                path: 'user/list', // /admin/user/add-new
                component: () => import('../views/admin/UserView.vue'),
                meta: {
                    title: '用户管理'
                }
            },
            {
                path: 'role/list', // /admin/user/list
                component: () => import('../views/admin/RoleView.vue'),
                meta: {
                    title: '角色管理'
                }
            },
            {
                path: 'permission/list', // /admin/user/add-new
                component: () => import('../views/admin/PermissionView.vue'),
                meta: {
                    title: '权限管理'
                }
            }

        ]
    },
    {
        path: '/manage',
        redirect: '/manage/product/list',
        component: () => import('../views/AdminView.vue'),
        children: [
            {
                path: 'product/list', //     /manage/product/list
                component: () => import('../views/manage/ProductView.vue'),
                meta: {
                    title: '商品管理'
                }
            },
            {
                path: 'categorys/list', //     /manage/categorys/list
                component: () => import('../views/manage/CategorysView.vue'),
                meta: {
                    title: '分类管理'
                }
            },
            {
                path: 'order/list', //     /manage/order/list
                component: () => import('../views/manage/OrderView.vue'),
                meta: {
                    title: '订单管理'
                }
            },
            {
                path: 'purchase/list', //     /manage/purchase/list
                component: () => import('../views/manage/PurchaseView.vue'),
                meta: {
                    title: '采购管理'
                }
            },
            {
                path: 'count/list', //     /admin/count/list
                component: () => import('../views/manage/CountView.vue'),
                meta: {
                    title: '统计管理'
                }
            }

        ]
    }


]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
    }
    next()
})

export default router
